package mzt;

import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class CollPic {
	public static void main(String[] args) {
		String url = "http://www.mzitu.com/japan/page/";// args[0];
		int pageCount = Utils.getNumByUrl(url + 1, Constant.PAGE_PIC_PAGE_CLASS);
		for (int i = 3; i <= 4; i++) {
			ArrayList<String> page = getPageList(url + i);

			download(page);
			try {
				TimeUnit.SECONDS.sleep(3);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}

	}

	private static void download(ArrayList<String> page) {
		for (String string : page) {

			System.out.println("-------------------------线程----------" + string);
			new Thread(new DownLoadPicTread(string)).start();
			try {
				TimeUnit.SECONDS.sleep(3);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}

		}
	}

	/**
	 * 获取每一页全部的图片 URL，为后抓取做准备
	 * 
	 * @param url
	 * @return
	 */
	private static ArrayList<String> getPageList(String url) {
		Element picUI = Jsoup.parse(Utils.connReturnBody(url)).getElementById(Constant.PAGE_PIC_UI_ID);
		Elements picLi = picUI.getElementsByTag("li");
		ArrayList<String> arrayList = new ArrayList<>();
		for (Element ele : picLi) {
			arrayList.add(ele.getElementsByTag("a").get(0).attr("href"));
		}
		return arrayList;
	}

	/**
	 * 获得url里面的body
	 * 
	 * @param url
	 */

}
